﻿@using Easy.CMS.Article
@using Easy.ViewPort.jsTree
@using Easy.Web.CMS.Article.Models
@{
    Script.Reqiured("jsTree").AtFoot();
    var articleTree = Html.Tree<ArticleType>().Source("GetArticleTypeTree", "ArticleType", new {module = "admin"});
    if (Authorizer.Authorize(PermissionKeys.ManageArticleType))
    {
        articleTree
        .AddPlugin(Plugins.ContextMenu)
            .AddContextMenuItem(new ContextmenuItem {Label = "新建", Action = "Create", Icon = "glyphicon glyphicon-plus"})
            .AddContextMenuItem(new ContextmenuItem {Label = "编辑", Action = "Edit", Icon = "glyphicon glyphicon-edit"});
    }
}
<div class="panel  panel-default">
    <div class="panel-heading">
        文章类别
    </div>
    <div class="panel-body">
        @articleTree
    </div>
    @if (Authorizer.Authorize(PermissionKeys.ManageArticleType))
    {
        <div class="panel-footer">
            <a href="@Url.Action("Create")" class="btn btn-link btn-xs">
                <i class="glyphicon glyphicon-plus"></i>
                添加类别
            </a>
        </div>
    }
</div>


<script type="text/javascript">
    function Create(node) {
        var parent = node.reference.attr("id");
        window.location.href = '@Url.Action("Create", "ArticleType", new { module = "admin" })' + '?ParentID=' + parent;
    }
    function Edit(node) {
        var id = node.reference.attr("id");
        window.location.href = '@Url.Action("Edit", "ArticleType", new { module = "admin" })' + '/' + id;
    }


</script>
